<?php


if (!defined('BASEPATH'))
	exit('No direct script access allowed');

class m_dokter extends CI_Model {

	function ambil() {
		$ambil = $this->db->get('dokterhewan');
		if ($ambil->num_rows() > 0) {
			foreach ($ambil->result() as $data) {
				$hasil[] = $data;
			}
			return $hasil;
		}
	}

	function tambah(){
		$nama = $this->input->post('nama');
		$nik = $this->input->post('nik');
		$data1 = array('nama' => $nama,'nik' => $nik);
		if($this->cek_nik($nik) == false) {
			$this->db->trans_start();
			$this->db->insert('dokterhewan', $data1);
			$this->db->trans_complete();
			$this->session->set_flashdata('result_pass_true', 'Data Dokter Hewan berhasil ditambahkan');
            header('location:' . site_url('dashboard/edit_profil'));
		} else{
			$this->session->set_flashdata('result_pass', 'NIK Dokter sudah ada');
            header('location:' . site_url('dashboard/edit_profil'));
		}
	}

	function hapus($a) {
		$this->db->trans_start();
		$this->db->delete('dokterhewan', array('id_dokterhewan' => $a));
		$this->db->trans_complete();
		return;
	}

	function cek_nik($nik=""){
		$ambil = $this->db->get_where('dokterhewan', array('nik' => $nik));
		if($ambil->num_rows > 0){
			return true;
		}else{
			return false;
		}
	}


	function ambilbyid($id="") {
		$ambil = $this->db->get_where('dokterhewan', array('id_dokterhewan' => $id));
		return $ambil;
	}




	function update($id="")
	{
		$nik = $this->input->post('nik');
		$nama = $this->input->post('nama');
		$data1 = array('nik' => $nik,'nama' => $nama);
		//transact sql e bro
		$this->db->trans_start();
		$this->db->where('id_dokterhewan', $id);
		$this->db->update('dokterhewan', $data1);
		$this->db->trans_complete();
		$this->session->set_flashdata('result_pass_true', 'Data Dokter Hewan berhasil diperbarui');
        header('location:' . site_url('penyakit/edit'.$id));

	}
        
        function logindokter($username, $nik) {
		$cek_login = $this->db->get_where('dokterhewan', array('nama' => $username, 'nik' => $nik));
		if (count($cek_login->result()) > 0) {
			foreach ($cek_login->result_array() as $data) {
				$hasil[] = $data;
			}
			return true;
		} else {
			return false;
		}
	}

}